<template>
    <div class="e-table billList">
        <div class="top">
            <div class="left">
                <div class="listTop">
                    <el-button
                        size="small"
                        class="btn-greenYellow"
                        @click="openAddDialog"
                    >
                        新增</el-button
                    >
                </div>
            </div>
            <div class="right">
                <div class="right-div1">
                    <el-input
                        placeholder="请输入关键字"
                        size="small"
                        v-model="pagination.query"
                        @blur="search"
                    >
                        <i slot="suffix" class="el-input__icon el-icon-search" @click="search"></i>
                    </el-input>
                </div>
                <div>
                    <el-button
                        size="small"
                        style="background: #2e61d7; color: #fff"
                        @click="dialogVisibleSearch = true"
                        >高级搜索
                    </el-button>
                </div>
            </div>
        </div>
        <el-table
            class="table"
            :data="tableData"
            border
            style="width: 100%"
            highlight-current-row
        >
            <el-table-column
                prop="title"
                label="标题"
                min-width="200"
                show-overflow-tooltip
            >
             <template slot-scope="scope">
                    <span
                        @click="tableDbShow(scope.row)"
                        style="color: blue; cursor: pointer"
                    >
                        {{ scope.row.title }}
                    </span>
                </template>
            </el-table-column>
             <el-table-column
                prop="billDate"
                label="日期"
                width="150"
            >
            </el-table-column>
            <el-table-column
                prop="orgName"
                label="机构"
                align="center"
                min-width="200"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="state"
                label="状态"
                width="150"
            >
                <template slot-scope="{ row }">
                    <span>{{ statusLable(row.state) }}</span>
                </template>
            </el-table-column>
        </el-table>
        <ComPagination
            :total="totalPage"
            :pageSize.sync="pagination.limit"
            :currentPage.sync="pagination.page"
            @currentChange="listByEntity"
            @sizeChange="listByEntity"
            class="bottomSetting"
        />
    </div>
</template>

<script>
import request from '@/api/equip/dailyManagement.js'
import ComPagination from '@/components/pagination/pagination.vue'
import { mapState } from 'vuex'
import { vueDom, debounce } from '@/utils/common.js'
import { getCurrentUnitInfo } from '@/api/equip/dailyManagementAudit.js'
export default {
    data () {
        return {
            tableData: [],
            totalPage: 0, //总页数
            tableHeight: 0,
            pagination: {
                'endTime': '',
                'founderId': '',
                'keyword': '',
                'limit': 20,
                'loginOrgId': '',
                'orgId': '',
                'page': 1,
                'startTime': '',
                'states': [],
                'title': ''
            },
            auditState: {}, //流程按钮显示状态
            auditParams: {
                'billId': '',
                'billType': 3014,
                'freeNextUnitIndex': null,
                'freeNextUser': '',
                'isPass': true,
                'isShareInAudit': true,
                'opinion': '',
                'orgId': '',
                'orgName': '',
                'userId': '',
                'workId': ''
            }

        }
    },
    components: {
        ComPagination
    },
    computed: {
        ...mapState({
            maintenanceType: state=>state.equip.equipData.maintenanceType, //维保类型
        }),
        statusLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.state//传财务单据状态
                const obj = state.find(x=>x.value === param)
                return obj.label
            }
        },
    },
    created () {
        this.getList()

    },
    mounted () {
        // table动态高度
        vueDom(
            () => {
                this.tableHeight = document.body.clientHeight - 170
            },
            () => {
                return $('table').length !== 0
            }
        )
        this.fn = () => {
            this.tableHeight = document.body.clientHeight - 170
        }
        window.onresize = debounce(this.fn)
    },
    methods: {
        //获取当前使用的字典
        getDicValue () {
            this.$store.dispatch('equip/setMaintenanceType')//更新维保类型
        },
        getList () {
            request.otherList(this.pagination).then(res=>{
                this.tableData = res.list
                this.totalPage = res.totalCount
            })
        },
        //分页查询
        listByEntity () {
            this.getList()
        },
        //模糊搜索
        search () {
            this.getList()
        },
        //新增
        openAddDialog () {
            this.$router.push('/otherAdd')
        },
        //查看
        tableDbShow (row) {
            if(row.state === -1 || row.state === 2 || row.state === 5) {
                this.$router.push({
                    path: '/otherShow',
                    query: { billid: row.billId }
                })
            }else{
                this.auditParams.billId = row.billId
                getCurrentUnitInfo(this.auditParams).then(res => {
                    this.auditState = res
                    if( this.auditState.canModify) {
                        this.$router.push({
                            path: '/otherEdit',
                            query: { billid: row.billId }
                        })
                    }else{
                        this.$router.push({
                            path: '/otherShow',
                            query: { billid: row.billId }
                        })
                    }
                })
            }
        },
    }
}
</script>

<style lang="scss" scoped>
</style>
